<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Api v1.0 docs</title>
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet" type="text/css">
    <link th:href="@{/css/bootstrap-responsive.min.css}" rel="stylesheet" type="text/css">
    <link th:href="@{/css/maruti-media.css}" rel="stylesheet" type="text/css">
    <link th:href="@{/css/maruti-style.css}" rel="stylesheet" type="text/css">
    <link th:href="@{/css/uniform.css}" rel="stylesheet" type="text/css">
    <link th:href="@{/css/jquery.gritter.css}" rel="stylesheet" type="text/css">
    <link th:href="@{/css/api.css}" rel="stylesheet" type="text/css">
    <script th:src="@{/javascript/jquery/jquery.min.js}" type="text/javascript"></script>
    <script th:src="@{/javascript/jquery/jquery.ui.custom.js}" type="text/javascript"></script>
    <script th:src="@{/javascript/jquery/jquery.gritter.min.js}" type="text/javascript"></script>
    <script th:src="@{/javascript/jquery/jquery.zxxbox.js}" type="text/javascript"></script>
    <script th:src="@{/javascript/jquery/bootstrap.min.js}" type="text/javascript"></script>
    <script th:src="@{/javascript/maruti.js}" type="text/javascript"></script>
    <script th:src="@{/javascript/desktopnotify.js}" type="text/javascript"></script>
</head>
<body>
<div id="content" style="margin-top: 0;">
    <div class="widget-content notify-ui">
        <ul id="gritter-notify">
            <li class="normal"><h3>Api v1.0 docs</h3></li>
        </ul>
    </div>
    <div class="alert alert-info">
        <p><strong>说明!</strong>&nbsp;&nbsp;<a href="/druid/index.html" target="_blank">Druid数据库监控</a> </p>

        <p>1.API地址为：http://domain/api/v1</p>
        <p>2.默认参数method决定具体接口</p>
        <p>
            3.微信的openId及用户的userId一律localStorage到本地，若发现没有这两个值，跳转到http://domain/wechat?url=要打开的链接，处理完成后，会自动跳到要打开的链接并在链接后面带上openId和userId，拿到再存储到本地。</p>
        <p>4.类型枚举字符串区分大小写</p>

    </div>
    <div class="widget-box">
        <div class="widget-title">
            <ul class="nav nav-tabs">
                <th:block th:each="apiType:${apiTypes}">
                    <li class="">
                        <a th:href="${'#'+apiType.methodType}" data-toggle="tab" th:text="${apiType.methodType.label+'接口'}"></a>
                    </li>
                </th:block>
                <li class=""><a href="#FILEUPLOADC" data-toggle="tab">文件上传</a></li>
            </ul>
        </div>
        <div class="widget-content tab-content">
            <th:block th:each="apiType:${apiTypes}">
                <div class="tab-pane" th:id="${apiType.methodType}">
                    <div>
                        <th:block  th:each="api:${apiType.apis}">
                            <a th:href="${'#'+api.method}" class="btn btn-info btn" th:text="${'#'+api.method.label}"></a>
                        </th:block>
                    </div>
                    <table class="table table-bordered data-table dataTable" style="margin-top: 5px;">
                        <thead>
                        <tr>
                            <td>接口名称</td>
                            <td>测试表单</td>
                            <td style="width: 350px;">参数&说明</td>
                            <td style="width: 350px;">返回结果</td>
                        </tr>
                        </thead>
                        <tbody th:each="api:${apiType.apis}">
                        <tr>
                            <td th:id="${api.method}">
                                <span class="label label-important" th:if="${api.authority}" th:text="'需要'+${api.roles}+'权限'"></span><br>
                                <span class="label label-important" th:if="${api.deprecated}">已过期</span><br>
                                <span th:text="${api.method.label}"></span><br/><span th:text="'method='+${api.method}"></span>
                            </td>
                            <td>
                                <form th:action="'/api/v1/' + ${api.method}" method="post" target="_blank">
                                    <th:block th:each="p:${api.parameter.paramList}">
                                        <p>
                                            <span th:text="${p}+'： '"></span>
                                            <input type="text" value="" th:name="${p}" class=""/>
                                        </p>
                                    </th:block>
                                    <p>
                                        <input type="submit" value="提交" class="">
                                    </p>
                                </form>
                            </td>
                            <td>
                                参数：
                                <ul>
                                    <th:block th:each="n:${api.parameter.paramNotes}">
                                        <li th:utext="${n}"></li>
                                    </th:block>
                                </ul>
                                返回：<br>
                                <ul>
                                    <li>状态值status</li>
                                    <li>辅助代码code</li>
                                    <li>结果对象</li>
                                </ul>
                            </td>
                            <td><pre th:text="${api.result}" class="json"></pre></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </th:block>
            <div class="tab-pane" id="FILEUPLOADC">
                <div>
                    <a href="#FILEUPLOAD" class="btn btn-info btn">#文件上传</a>
                </div>
                <table class="table table-bordered data-table dataTable" style="margin-top: 5px;">
                    <thead>
                    <tr>
                        <td>接口名称</td>
                        <td>测试表单</td>
                        <td style="width: 350px;">参数&说明</td>
                        <td style="width: 350px;">返回结果</td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td id="FILEUPLOAD" style="width: 20%">
                            文件上传<br/>请求地址：http://domain/file.upload
                        </td>
                        <td>
                            <form action="/file.upload" method="POST" target="_blank" enctype="multipart/form-data">
                                <p>
                                    <span>选择文件： </span>
                                    <input type="file" name="userfile">
                                </p>
                                <p>
                                    <span>X： </span>
                                    <label>
                                        <input type="text" value="" name="x" class="">
                                    </label>
                                </p>
                                <p>
                                    <span>Y： </span>
                                    <label>
                                        <input type="text" value="" name="y" class="">
                                    </label>
                                </p>
                                <p>
                                    <span>宽度： </span>
                                    <label>
                                        <input type="text" value="" name="w" class="">
                                    </label>
                                </p>
                                <p>
                                    <span>高度： </span>
                                    <label>
                                        <input type="text" value="" name="h" class="">
                                    </label>
                                </p>
                                <p>
                                    <input type="submit" value="提交" class="">
                                </p>
                            </form>
                        </td>
                        <td>
                            参数：
                            <ul>
                                <li>userfile，文件，每次只传一个文件</li>
                                <li>x，裁剪坐标x</li>
                                <li>y，裁剪坐标y</li>
                                <li>w，裁剪宽度</li>
                                <li>h，裁剪高度</li>
                            </ul>
                            返回：<br>
                            <ul>
                                <li>状态值status</li>
                                <li>辅助代码code</li>
                                <li>文件链接</li>
                            </ul>
                        </td>
                        <td>上传成功后的链接</td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $(".nav-tabs li:first").addClass("active");
        $(".tab-pane:first").addClass("active");
        $(".json").each(function () {
            try {
                var json = JSON.parse($(this).html());
                $(this).html(syntaxHighlight(json))
            } catch (e) {
            }
        });
    });

    function syntaxHighlight(json) {
        if (typeof json !== 'string') {
            json = JSON.stringify(json, undefined, 2);
        }
        json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
        return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
            var cls = 'number';
            if (/^"/.test(match)) {
                if (/:$/.test(match)) {
                    cls = 'key';
                } else {
                    cls = 'string';
                }
            } else if (/true|false/.test(match)) {
                cls = 'boolean';
            } else if (/null/.test(match)) {
                cls = 'null';
            }
            return '<span class="' + cls + '">' + match + '</span>';
        });
    }
</script>
</body>
</html>
